package com.dev.mainual.throwable.ssm;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.Map;

/**
 * ClassName: GlobalExceptionAdvice
 * Description: 统一异常
 * Date: 2019/1/28 12:39 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionAdvice {


    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String error() {
        return "/error/500";
    }


    @ResponseStatus(HttpStatus.NOT_FOUND)
    public String notFound() {
        return "/error/404";
    }


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Map<String, Object> exception(Exception ex) {


        // 消息组装 ... ...

        // 异常日志记录
        log.error(ex.getMessage(), ex);
        return null;
    }
}